package com.redrose.flutterdemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.redrose.flutterdemo.R;
import com.redrose.flutterdemo.bean.Photo;
import com.redrose.flutterdemo.camera.BigImageActivity;
import com.redrose.flutterdemo.utils.GlideUtils;
import com.redrose.flutterdemo.utils.ToolUtils;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

/**
 * Desc:
 *
 * @author: RedRose
 * Date: 2019/4/1
 * Email: yinsxi@163.com
 */

public class ItemImageAdapter extends CommonAdapter<Photo> {
    private Context mContext;
    public ItemImageAdapter(Context context, int layoutId, List<Photo> datas) {
        super(context, layoutId, datas);
        this.mContext = context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, Photo item, int position) {
        ImageView imageView = viewHolder.getView(R.id.imageView);
        ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
        int width = ToolUtils.getWidth(mContext);
        int imageViewWidth = (width - ToolUtils.dp2px(mContext,35))/4;
        layoutParams.width = imageViewWidth;
        layoutParams.height = imageViewWidth;
        GlideUtils.load(imageView,item.getPath());
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, BigImageActivity.class);
                intent.putExtra("photoData",item);
                mContext.startActivity(intent);
            }
        });
    }
}
